
##################Figures Appendix - Campbell and Spilker "Aiding Peace"#################


library(stringr)
library(dplyr)
library(ggplot2)
library(grid)
library(gtable) 
library(readr)


##############
##  Figure 6 ##
##############


ptacr <- read_delim("ttest_figure_r.txt", 
                    "\t", escape_double = FALSE, trim_ws = TRUE)



# Create intervals
clo <- ptacr$dif - 1.96*ptacr$se
chi <- ptacr$dif + 1.96*ptacr$se

#Create categories
ptacr$categories <- c(rep("Humanitarian",3),
                      rep("Transitional",3),
                      rep("Development",3),
                      rep("Budgetary",3)
              )
                      

ptacr$categories <- factor(ptacr$categories,
                           levels = c( "Humanitarian",
                                      "Transitional",
                                      "Development",
                                      "Budgetary"))

# Create new labels

  ptacr$labels <- c("Strong Violence", "Mild Violence", "Mild Peace" ,
                   "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", 
               	 "Mild Peace")

ptacr$labels <- factor(ptacr$labels,          
                       levels = c("Mild Peace", "Mild Violence",  "Strong Violence",
                                                         "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence"))
  
category_shortnames <- c(
  `Humanitarian` = "Humanitarian",
  `Transitional` = "Transitional",
  `Development` = "Development",
  `Budgetary` = "Budgetary"
)



##########################################################################
# Plot 

base <- ggplot(ptacr, aes(y = ptacr$labels, x = ptacr$dif,
                          group=ptacr$categories)) +
  geom_point(size=1.5) +
  geom_errorbarh(aes(xmax = clo, xmin = chi, height = 0)) +
  theme_bw() +
  geom_vline(xintercept = 0, colour = "black", linetype = 2, size = .7) +
  facet_grid(categories ~ ., labeller = as_labeller(category_shortnames),
             scales  ="free_y", space = "free_y", switch = "both") +
  scale_y_discrete(position="right") +
  theme(plot.background = element_rect(fill = 'grey95'),
        axis.text.x = element_text(size=11, color = "black"),
        axis.text.y = element_text(size=8.5, color = "black"),
        strip.text.y = element_text(angle = 180, color = "grey15", size = 8.5),
        strip.background = element_rect(fill = 'grey85')) +
  theme(axis.title.y = element_blank(),
        plot.margin=unit(c(1,1,1,3),"line")) +
  #scale_x_continuous(labels = c("-2","-1","-0.5","0","0.5", "1", "1.5")) +
  scale_x_continuous(limits=c(-1.5, 1.5)) +
  xlab("Difference in Means (Baseline: Strong Peace)")

# Render plot
plot <- ggplotGrob(base)


# Final plot
grid.newpage()
grid.draw(plot)

dev.print(device = pdf, file="Figure_6.pdf")


##################Figure 7 -- Left Panel -- Scenario known#################

ptacr <- read_delim("ttest_figure_r_comb_known.txt", 
                    "\t", escape_double = FALSE, trim_ws = TRUE)



# Create intervals
clo <- ptacr$dif - 1.96*ptacr$se
chi <- ptacr$dif + 1.96*ptacr$se

#Create categories
ptacr$categories <- c(rep("Humanitarian",3),
                      rep("Transitional",3),
                      rep("Development",3),
                      rep("Budgetary",3)
              )
                      

ptacr$categories <- factor(ptacr$categories,
                           levels = c( "Humanitarian",
                                      "Transitional",
                                      "Development",
                                      "Budgetary"))

# Create new labels

  ptacr$labels <- c("Strong Violence", "Mild Violence", "Mild Peace" ,
                   "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", 
               	 "Mild Peace")

ptacr$labels <- factor(ptacr$labels,          
                       levels = c("Mild Peace", "Mild Violence",  "Strong Violence",
                                                         "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence"))
  
category_shortnames <- c(
  `Humanitarian` = "Humanitarian",
  `Transitional` = "Transitional",
  `Development` = "Development",
  `Budgetary` = "Budgetary"
)



##########################################################################
# Plot 

base <- ggplot(ptacr, aes(y = ptacr$labels, x = ptacr$dif,
                          group=ptacr$categories)) +
  geom_point(size=1.5) +
  geom_errorbarh(aes(xmax = clo, xmin = chi, height = 0)) +
  theme_bw() +
  geom_vline(xintercept = 0, colour = "black", linetype = 2, size = .7) +
  facet_grid(categories ~ ., labeller = as_labeller(category_shortnames),
             scales  ="free_y", space = "free_y", switch = "both") +
  scale_y_discrete(position="right") +
  theme(plot.background = element_rect(fill = 'grey95'),
        axis.text.x = element_text(size=11, color = "black"),
        axis.text.y = element_text(size=8.5, color = "black"),
        strip.text.y = element_text(angle = 180, color = "grey15", size = 8.5),
        strip.background = element_rect(fill = 'grey85')) +
  theme(axis.title.y = element_blank(),
        plot.margin=unit(c(1,1,1,3),"line")) +
  #scale_x_continuous(labels = c("-2","-1","-0.5","0","0.5", "1", "1.5")) +
  scale_x_continuous(limits=c(-1.5, 1.5)) +
  xlab("Scenario known")

# Render plot
plot <- ggplotGrob(base)


# Final plot
grid.newpage()
grid.draw(plot)

dev.print(device = pdf, file="Figure_7_left_Panel.pdf")


##################Figure 7 -- Right Panel -- Scenario unknown#################

ptacr <- read_delim("ttest_figure_r_comb_unkown.txt", 
                    "\t", escape_double = FALSE, trim_ws = TRUE)



# Create intervals
clo <- ptacr$dif - 1.96*ptacr$se
chi <- ptacr$dif + 1.96*ptacr$se

#Create categories
ptacr$categories <- c(rep("Humanitarian",3),
                      rep("Transitional",3),
                      rep("Development",3),
                      rep("Budgetary",3)
              )
                      

ptacr$categories <- factor(ptacr$categories,
                           levels = c( "Humanitarian",
                                      "Transitional",
                                      "Development",
                                      "Budgetary"))

# Create new labels

  ptacr$labels <- c("Strong Violence", "Mild Violence", "Mild Peace" ,
                   "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", 
               	 "Mild Peace")

ptacr$labels <- factor(ptacr$labels,          
                       levels = c("Mild Peace", "Mild Violence",  "Strong Violence",
                                                         "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence"))
  
category_shortnames <- c(
  `Humanitarian` = "Humanitarian",
  `Transitional` = "Transitional",
  `Development` = "Development",
  `Budgetary` = "Budgetary"
)



##########################################################################
# Plot 

base <- ggplot(ptacr, aes(y = ptacr$labels, x = ptacr$dif,
                          group=ptacr$categories)) +
  geom_point(size=1.5) +
  geom_errorbarh(aes(xmax = clo, xmin = chi, height = 0)) +
  theme_bw() +
  geom_vline(xintercept = 0, colour = "black", linetype = 2, size = .7) +
  facet_grid(categories ~ ., labeller = as_labeller(category_shortnames),
             scales  ="free_y", space = "free_y", switch = "both") +
  scale_y_discrete(position="right") +
  theme(plot.background = element_rect(fill = 'grey95'),
        axis.text.x = element_text(size=11, color = "black"),
        axis.text.y = element_text(size=8.5, color = "black"),
        strip.text.y = element_text(angle = 180, color = "grey15", size = 8.5),
        strip.background = element_rect(fill = 'grey85')) +
  theme(axis.title.y = element_blank(),
        plot.margin=unit(c(1,1,1,3),"line")) +
  #scale_x_continuous(labels = c("-2","-1","-0.5","0","0.5", "1", "1.5")) +
  scale_x_continuous(limits=c(-1.5, 1.5)) +
  xlab("Scenario unknown")

# Render plot
plot <- ggplotGrob(base)


# Final plot
grid.newpage()
grid.draw(plot)

dev.print(device = pdf, file="Figure_7_right_panel.pdf")



##################Figure 8 -- Left Panel -- Donors#################

ptacr <- read_delim("ttest_figure_R_donors.txt", 
                    "\t", escape_double = FALSE, trim_ws = TRUE)


# Create intervals
clo <- ptacr$dif - 1.96*ptacr$se
chi <- ptacr$dif + 1.96*ptacr$se

#Create categories
ptacr$categories <- c(rep("Humanitarian",3),
                      rep("Transitional",3),
                      rep("Development",3),
                      rep("Budgetary",3)
)


ptacr$categories <- factor(ptacr$categories,
                           levels = c( "Humanitarian",
                                       "Transitional",
                                       "Development",
                                       "Budgetary"))

# Create new labels

ptacr$labels <- c("Strong Violence", "Mild Violence", "Mild Peace" ,
                  "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", 
                  "Mild Peace")

ptacr$labels <- factor(ptacr$labels,          
                       levels = c("Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence"))

category_shortnames <- c(
  `Humanitarian` = "Humanitarian",
  `Transitional` = "Transitional",
  `Development` = "Development",
  `Budgetary` = "Budgetary"
)



##########################################################################
# Plot 

base <- ggplot(ptacr, aes(y = ptacr$labels, x = ptacr$dif,
                          group=ptacr$categories)) +
  geom_point(size=1.5) +
  geom_errorbarh(aes(xmax = clo, xmin = chi, height = 0)) +
  theme_bw() +
  geom_vline(xintercept = 0, colour = "black", linetype = 2, size = .7) +
  facet_grid(categories ~ ., labeller = as_labeller(category_shortnames),
             scales  ="free_y", space = "free_y", switch = "both") +
  scale_y_discrete(position="right") +
  theme(plot.background = element_rect(fill = 'grey95'),
        axis.text.x = element_text(size=11, color = "black"),
        axis.text.y = element_text(size=8.5, color = "black"),
        strip.text.y = element_text(angle = 180, color = "grey15", size = 8.5),
        strip.background = element_rect(fill = 'grey85')) +
  theme(axis.title.y = element_blank(),
        plot.margin=unit(c(1,1,1,3),"line")) +
  #scale_x_continuous(labels = c("-1.5","-1","-0.5","0","0.5", "1", "1.5")) +
  scale_x_continuous(limits=c(-1.5, 2)) +
  xlab("Donors")

# Render plot
plot <- ggplotGrob(base)


# Final plot
grid.newpage()
grid.draw(plot)

dev.print(device = pdf, file="Figure_8_Left_Panel.pdf")



##################Figure 8 -- Right Panel -- Implementing Agencies#################

ptacr <- read_delim("ttest_figure_R_impl.txt", 
                    "\t", escape_double = FALSE, trim_ws = TRUE)



# Create intervals
clo <- ptacr$dif - 1.96*ptacr$se
chi <- ptacr$dif + 1.96*ptacr$se

#Create categories
ptacr$categories <- c(rep("Humanitarian",3),
                      rep("Transitional",3),
                      rep("Development",3),
                      rep("Budgetary",3)
              )
                      

ptacr$categories <- factor(ptacr$categories,
                           levels = c( "Humanitarian",
                                      "Transitional",
                                      "Development",
                                      "Budgetary"))

# Create new labels

  ptacr$labels <- c("Strong Violence", "Mild Violence", "Mild Peace" ,
                   "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", 
               	 "Mild Peace")

ptacr$labels <- factor(ptacr$labels,          
                       levels = c("Mild Peace", "Mild Violence",  "Strong Violence",
                                                         "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence"))
  
category_shortnames <- c(
  `Humanitarian` = "Humanitarian",
  `Transitional` = "Transitional",
  `Development` = "Development",
  `Budgetary` = "Budgetary"
)



##########################################################################
# Plot 

base <- ggplot(ptacr, aes(y = ptacr$labels, x = ptacr$dif,
                          group=ptacr$categories)) +
  geom_point(size=1.5) +
  geom_errorbarh(aes(xmax = clo, xmin = chi, height = 0)) +
  theme_bw() +
  geom_vline(xintercept = 0, colour = "black", linetype = 2, size = .7) +
  facet_grid(categories ~ ., labeller = as_labeller(category_shortnames),
             scales  ="free_y", space = "free_y", switch = "both") +
  scale_y_discrete(position="right") +
  theme(plot.background = element_rect(fill = 'grey95'),
        axis.text.x = element_text(size=11, color = "black"),
        axis.text.y = element_text(size=8.5, color = "black"),
        strip.text.y = element_text(angle = 180, color = "grey15", size = 8.5),
        strip.background = element_rect(fill = 'grey85')) +
  theme(axis.title.y = element_blank(),
        plot.margin=unit(c(1,1,1,3),"line")) +
  #scale_x_continuous(labels = c("-2","-1","-0.5","0","0.5", "1", "1.5")) +
  scale_x_continuous(limits=c(-1.5, 2)) +
  xlab("Implementing Agencies")

# Render plot
plot <- ggplotGrob(base)


# Final plot
grid.newpage()
grid.draw(plot)

dev.print(device = pdf, file="Figure_8_Right_Panel.pdf")



##################Figure 9 -- Left Panel -- Implementing Agencies -- Scenario Known#################

ptacr <- read_delim("ttest_figure_r_scenario_known_impl.txt", 
                    "\t", escape_double = FALSE, trim_ws = TRUE)


# Create intervals
clo <- ptacr$dif - 1.96*ptacr$se
chi <- ptacr$dif + 1.96*ptacr$se

#Create categories
ptacr$categories <- c(rep("Humanitarian",3),
                      rep("Transitional",3),
                      rep("Development",3),
                      rep("Budgetary",3)
)


ptacr$categories <- factor(ptacr$categories,
                           levels = c( "Humanitarian",
                                       "Transitional",
                                       "Development",
                                       "Budgetary"))

# Create new labels

ptacr$labels <- c("Strong Violence", "Mild Violence", "Mild Peace" ,
                  "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", 
                  "Mild Peace")

ptacr$labels <- factor(ptacr$labels,          
                       levels = c("Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence"))

category_shortnames <- c(
  `Humanitarian` = "Humanitarian",
  `Transitional` = "Transitional",
  `Development` = "Development",
  `Budgetary` = "Budgetary"
)



##########################################################################
# Plot 

base <- ggplot(ptacr, aes(y = ptacr$labels, x = ptacr$dif,
                          group=ptacr$categories)) +
  geom_point(size=1.5) +
  geom_errorbarh(aes(xmax = clo, xmin = chi, height = 0)) +
  theme_bw() +
  geom_vline(xintercept = 0, colour = "black", linetype = 2, size = .7) +
  facet_grid(categories ~ ., labeller = as_labeller(category_shortnames),
             scales  ="free_y", space = "free_y", switch = "both") +
  scale_y_discrete(position="right") +
  theme(plot.background = element_rect(fill = 'grey95'),
        axis.text.x = element_text(size=11, color = "black"),
        axis.text.y = element_text(size=8.5, color = "black"),
        strip.text.y = element_text(angle = 180, color = "grey15", size = 8.5),
        strip.background = element_rect(fill = 'grey85')) +
  theme(axis.title.y = element_blank(),
        plot.margin=unit(c(1,1,1,3),"line")) +
  scale_x_continuous(limits=c(-1.5, 2)) +
  #scale_x_continuous(labels = c("-.2","-.1","0",".1")) +
  xlab("Implementing Agencies -- Scenario known")

# Render plot
plot <- ggplotGrob(base)


# Final plot
grid.newpage()
grid.draw(plot)

dev.print(device = pdf, file="Figure_9_Left_Panel.pdf")



##################Figure 9 -- Right Panel -- Implementing Agencies -- Scenario Unknown#################

ptacr <- read_delim("ttest_figure_r_scenario_unknown_impl.txt", 
                    "\t", escape_double = FALSE, trim_ws = TRUE)


# Create intervals
clo <- ptacr$dif - 1.96*ptacr$se
chi <- ptacr$dif + 1.96*ptacr$se

#Create categories
ptacr$categories <- c(rep("Humanitarian",3),
                      rep("Transitional",3),
                      rep("Development",3),
                      rep("Budgetary",3)
)


ptacr$categories <- factor(ptacr$categories,
                           levels = c( "Humanitarian",
                                       "Transitional",
                                       "Development",
                                       "Budgetary"))

# Create new labels

ptacr$labels <- c("Strong Violence", "Mild Violence", "Mild Peace" ,
                  "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", 
                  "Mild Peace")

ptacr$labels <- factor(ptacr$labels,          
                       levels = c("Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence"))

category_shortnames <- c(
  `Humanitarian` = "Humanitarian",
  `Transitional` = "Transitional",
  `Development` = "Development",
  `Budgetary` = "Budgetary"
)



##########################################################################
# Plot 

base <- ggplot(ptacr, aes(y = ptacr$labels, x = ptacr$dif,
                          group=ptacr$categories)) +
  geom_point(size=1.5) +
  geom_errorbarh(aes(xmax = clo, xmin = chi, height = 0)) +
  theme_bw() +
  geom_vline(xintercept = 0, colour = "black", linetype = 2, size = .7) +
  facet_grid(categories ~ ., labeller = as_labeller(category_shortnames),
             scales  ="free_y", space = "free_y", switch = "both") +
  scale_y_discrete(position="right") +
  theme(plot.background = element_rect(fill = 'grey95'),
        axis.text.x = element_text(size=11, color = "black"),
        axis.text.y = element_text(size=8.5, color = "black"),
        strip.text.y = element_text(angle = 180, color = "grey15", size = 8.5),
        strip.background = element_rect(fill = 'grey85')) +
  theme(axis.title.y = element_blank(),
        plot.margin=unit(c(1,1,1,3),"line")) +
  #scale_x_continuous(labels = c("-.2","-.1","0",".1")) +
  scale_x_continuous(limits=c(-1.5, 2)) +
  xlab("Implementing Agencies -- Scenario unkown")

# Render plot
plot <- ggplotGrob(base)


# Final plot
grid.newpage()
grid.draw(plot)

dev.print(device = pdf, file="Figure_9_Right_Panel.pdf")




##################Figure 10 -- Left Panel -- Donors -- Scenario Known#################

ptacr <- read_delim("ttest_figure_R_yes_scenario_donors.txt", 
                    "\t", escape_double = FALSE, trim_ws = TRUE)


# Create intervals
clo <- ptacr$dif - 1.96*ptacr$se
chi <- ptacr$dif + 1.96*ptacr$se

#Create categories
ptacr$categories <- c(rep("Humanitarian",3),
                      rep("Transitional",3),
                      rep("Development",3),
                      rep("Budgetary",3)
)


ptacr$categories <- factor(ptacr$categories,
                           levels = c( "Humanitarian",
                                       "Transitional",
                                       "Development",
                                       "Budgetary"))

# Create new labels

ptacr$labels <- c("Strong Violence", "Mild Violence", "Mild Peace" ,
                  "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", 
                  "Mild Peace")

ptacr$labels <- factor(ptacr$labels,          
                       levels = c("Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence"))

category_shortnames <- c(
  `Humanitarian` = "Humanitarian",
  `Transitional` = "Transitional",
  `Development` = "Development",
  `Budgetary` = "Budgetary"
)



##########################################################################
# Plot 

base <- ggplot(ptacr, aes(y = ptacr$labels, x = ptacr$dif,
                          group=ptacr$categories)) +
  geom_point(size=1.5) +
  geom_errorbarh(aes(xmax = clo, xmin = chi, height = 0)) +
  theme_bw() +
  geom_vline(xintercept = 0, colour = "black", linetype = 2, size = .7) +
  facet_grid(categories ~ ., labeller = as_labeller(category_shortnames),
             scales  ="free_y", space = "free_y", switch = "both") +
  scale_y_discrete(position="right") +
  theme(plot.background = element_rect(fill = 'grey95'),
        axis.text.x = element_text(size=11, color = "black"),
        axis.text.y = element_text(size=8.5, color = "black"),
        strip.text.y = element_text(angle = 180, color = "grey15", size = 8.5),
        strip.background = element_rect(fill = 'grey85')) +
  theme(axis.title.y = element_blank(),
        plot.margin=unit(c(1,1,1,3),"line")) +
  scale_x_continuous(limits=c(-1.5, 2)) +
  #scale_x_continuous(labels = c("-.2","-.1","0",".1")) +
  xlab("Donors -- Scenario known")

# Render plot
plot <- ggplotGrob(base)


# Final plot
grid.newpage()
grid.draw(plot)

dev.print(device = pdf, file="Figure_10_Left_Panel.pdf")



##################Figure 10 -- Right Panel -- Donors -- Scenario Unknown#################


ptacr <- read_delim("ttest_figure_R_no_scenario_donors.txt", 
                    "\t", escape_double = FALSE, trim_ws = TRUE)


# Create intervals
clo <- ptacr$dif - 1.96*ptacr$se
chi <- ptacr$dif + 1.96*ptacr$se

#Create categories
ptacr$categories <- c(rep("Humanitarian",3),
                      rep("Transitional",3),
                      rep("Development",3),
                      rep("Budgetary",3)
)


ptacr$categories <- factor(ptacr$categories,
                           levels = c( "Humanitarian",
                                       "Transitional",
                                       "Development",
                                       "Budgetary"))

# Create new labels

ptacr$labels <- c("Strong Violence", "Mild Violence", "Mild Peace" ,
                  "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", 
                  "Mild Peace")

ptacr$labels <- factor(ptacr$labels,          
                       levels = c("Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence"))

category_shortnames <- c(
  `Humanitarian` = "Humanitarian",
  `Transitional` = "Transitional",
  `Development` = "Development",
  `Budgetary` = "Budgetary"
)



##########################################################################
# Plot 

base <- ggplot(ptacr, aes(y = ptacr$labels, x = ptacr$dif,
                          group=ptacr$categories)) +
  geom_point(size=1.5) +
  geom_errorbarh(aes(xmax = clo, xmin = chi, height = 0)) +
  theme_bw() +
  geom_vline(xintercept = 0, colour = "black", linetype = 2, size = .7) +
  facet_grid(categories ~ ., labeller = as_labeller(category_shortnames),
             scales  ="free_y", space = "free_y", switch = "both") +
  scale_y_discrete(position="right") +
  theme(plot.background = element_rect(fill = 'grey95'),
        axis.text.x = element_text(size=11, color = "black"),
        axis.text.y = element_text(size=8.5, color = "black"),
        strip.text.y = element_text(angle = 180, color = "grey15", size = 8.5),
        strip.background = element_rect(fill = 'grey85')) +
  theme(axis.title.y = element_blank(),
        plot.margin=unit(c(1,1,1,3),"line")) +
  scale_x_continuous(limits=c(-1.5, 2)) +
  #scale_x_continuous(labels = c("-.2","-.1","0",".1")) +
  xlab("Donors -- Scenario Unknown")

# Render plot
plot <- ggplotGrob(base)


# Final plot
grid.newpage()
grid.draw(plot)

dev.print(device = pdf, file="Figure_10_Right_Panel.pdf")




##################Figure 11 -- Left Panel -- Implementing Agencies -- Priority Country#################

ptacr <- read_delim("ttest_figure_R_priority_impl.txt", 
                    "\t", escape_double = FALSE, trim_ws = TRUE)


# Create intervals
clo <- ptacr$dif - 1.96*ptacr$se
chi <- ptacr$dif + 1.96*ptacr$se

#Create categories
ptacr$categories <- c(rep("Humanitarian",3),
                      rep("Transitional",3),
                      rep("Development",3),
                      rep("Budgetary",3)
)


ptacr$categories <- factor(ptacr$categories,
                           levels = c( "Humanitarian",
                                       "Transitional",
                                       "Development",
                                       "Budgetary"))

# Create new labels

ptacr$labels <- c("Strong Violence", "Mild Violence", "Mild Peace" ,
                  "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", 
                  "Mild Peace")

ptacr$labels <- factor(ptacr$labels,          
                       levels = c("Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence"))

category_shortnames <- c(
  `Humanitarian` = "Humanitarian",
  `Transitional` = "Transitional",
  `Development` = "Development",
  `Budgetary` = "Budgetary"
)



##########################################################################
# Plot 

base <- ggplot(ptacr, aes(y = ptacr$labels, x = ptacr$dif,
                          group=ptacr$categories)) +
  geom_point(size=1.5) +
  geom_errorbarh(aes(xmax = clo, xmin = chi, height = 0)) +
  theme_bw() +
  geom_vline(xintercept = 0, colour = "black", linetype = 2, size = .7) +
  facet_grid(categories ~ ., labeller = as_labeller(category_shortnames),
             scales  ="free_y", space = "free_y", switch = "both") +
  scale_y_discrete(position="right") +
  theme(plot.background = element_rect(fill = 'grey95'),
        axis.text.x = element_text(size=11, color = "black"),
        axis.text.y = element_text(size=8.5, color = "black"),
        strip.text.y = element_text(angle = 180, color = "grey15", size = 8.5),
        strip.background = element_rect(fill = 'grey85')) +
  theme(axis.title.y = element_blank(),
        plot.margin=unit(c(1,1,1,3),"line")) +
  scale_x_continuous(limits=c(-1.5, 2)) +
  #scale_x_continuous(labels = c("-.2","-.1","0",".1")) +
  xlab("Implementing Agencies -- Priority Status")

# Render plot
plot <- ggplotGrob(base)


# Final plot
grid.newpage()
grid.draw(plot)

dev.print(device = pdf, file="Figure_11_Left_Panel.pdf")





##################Figure 11 -- Right Panel -- Implementing Agencies -- No Priority Country#################


ptacr <- read_delim("ttest_figure_R_no_priority_impl.txt", 
                    "\t", escape_double = FALSE, trim_ws = TRUE)


# Create intervals
clo <- ptacr$dif - 1.96*ptacr$se
chi <- ptacr$dif + 1.96*ptacr$se

#Create categories
ptacr$categories <- c(rep("Humanitarian",3),
                      rep("Transitional",3),
                      rep("Development",3),
                      rep("Budgetary",3)
)


ptacr$categories <- factor(ptacr$categories,
                           levels = c( "Humanitarian",
                                       "Transitional",
                                       "Development",
                                       "Budgetary"))

# Create new labels

ptacr$labels <- c("Strong Violence", "Mild Violence", "Mild Peace" ,
                  "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", 
                  "Mild Peace")

ptacr$labels <- factor(ptacr$labels,          
                       levels = c("Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence"))

category_shortnames <- c(
  `Humanitarian` = "Humanitarian",
  `Transitional` = "Transitional",
  `Development` = "Development",
  `Budgetary` = "Budgetary"
)



##########################################################################
# Plot 

base <- ggplot(ptacr, aes(y = ptacr$labels, x = ptacr$dif,
                          group=ptacr$categories)) +
  geom_point(size=1.5) +
  geom_errorbarh(aes(xmax = clo, xmin = chi, height = 0)) +
  theme_bw() +
  geom_vline(xintercept = 0, colour = "black", linetype = 2, size = .7) +
  facet_grid(categories ~ ., labeller = as_labeller(category_shortnames),
             scales  ="free_y", space = "free_y", switch = "both") +
  scale_y_discrete(position="right") +
  theme(plot.background = element_rect(fill = 'grey95'),
        axis.text.x = element_text(size=11, color = "black"),
        axis.text.y = element_text(size=8.5, color = "black"),
        strip.text.y = element_text(angle = 180, color = "grey15", size = 8.5),
        strip.background = element_rect(fill = 'grey85')) +
  theme(axis.title.y = element_blank(),
        plot.margin=unit(c(1,1,1,3),"line")) +
  scale_x_continuous(limits=c(-1.5, 2)) +
  #scale_x_continuous(labels = c("-.2","-.1","0",".1")) +
  xlab("Implementing Agencies -- No Priority Status")

# Render plot
plot <- ggplotGrob(base)


# Final plot
grid.newpage()
grid.draw(plot)

dev.print(device = pdf, file="Figure_11_Right_Panel.pdf")




##################Figure 12 -- Left Panel -- Donors -- Priority Country#################

ptacr <- read_delim("ttest_figure_R_priority_donors.txt", 
                    "\t", escape_double = FALSE, trim_ws = TRUE)


# Create intervals
clo <- ptacr$dif - 1.96*ptacr$se
chi <- ptacr$dif + 1.96*ptacr$se

#Create categories
ptacr$categories <- c(rep("Humanitarian",3),
                      rep("Transitional",3),
                      rep("Development",3),
                      rep("Budgetary",3)
)


ptacr$categories <- factor(ptacr$categories,
                           levels = c( "Humanitarian",
                                       "Transitional",
                                       "Development",
                                       "Budgetary"))

# Create new labels

ptacr$labels <- c("Strong Violence", "Mild Violence", "Mild Peace" ,
                  "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", 
                  "Mild Peace")

ptacr$labels <- factor(ptacr$labels,          
                       levels = c("Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence"))

category_shortnames <- c(
  `Humanitarian` = "Humanitarian",
  `Transitional` = "Transitional",
  `Development` = "Development",
  `Budgetary` = "Budgetary"
)



##########################################################################
# Plot 

base <- ggplot(ptacr, aes(y = ptacr$labels, x = ptacr$dif,
                          group=ptacr$categories)) +
  geom_point(size=1.5) +
  geom_errorbarh(aes(xmax = clo, xmin = chi, height = 0)) +
  theme_bw() +
  geom_vline(xintercept = 0, colour = "black", linetype = 2, size = .7) +
  facet_grid(categories ~ ., labeller = as_labeller(category_shortnames),
             scales  ="free_y", space = "free_y", switch = "both") +
  scale_y_discrete(position="right") +
  theme(plot.background = element_rect(fill = 'grey95'),
        axis.text.x = element_text(size=11, color = "black"),
        axis.text.y = element_text(size=8.5, color = "black"),
        strip.text.y = element_text(angle = 180, color = "grey15", size = 8.5),
        strip.background = element_rect(fill = 'grey85')) +
  theme(axis.title.y = element_blank(),
        plot.margin=unit(c(1,1,1,3),"line")) +
  scale_x_continuous(limits=c(-2, 2)) +
  #scale_x_continuous(labels = c("-.2","-.1","0",".1")) +
  xlab("Donors -- Priority Status")

# Render plot
plot <- ggplotGrob(base)


# Final plot
grid.newpage()
grid.draw(plot)

dev.print(device = pdf, file="Figure_12_Left_Panel.pdf")



##################Figure 12 -- Right Panel -- Donors -- No Priority Country#################


ptacr <- read_delim("ttest_figure_R_no_priority_donors.txt", 
                    "\t", escape_double = FALSE, trim_ws = TRUE)


# Create intervals
clo <- ptacr$dif - 1.96*ptacr$se
chi <- ptacr$dif + 1.96*ptacr$se

#Create categories
ptacr$categories <- c(rep("Humanitarian",3),
                      rep("Transitional",3),
                      rep("Development",3),
                      rep("Budgetary",3)
)


ptacr$categories <- factor(ptacr$categories,
                           levels = c( "Humanitarian",
                                       "Transitional",
                                       "Development",
                                       "Budgetary"))

# Create new labels

ptacr$labels <- c("Strong Violence", "Mild Violence", "Mild Peace" ,
                  "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", 
                  "Mild Peace")

ptacr$labels <- factor(ptacr$labels,          
                       levels = c("Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence"))

category_shortnames <- c(
  `Humanitarian` = "Humanitarian",
  `Transitional` = "Transitional",
  `Development` = "Development",
  `Budgetary` = "Budgetary"
)



##########################################################################
# Plot 

base <- ggplot(ptacr, aes(y = ptacr$labels, x = ptacr$dif,
                          group=ptacr$categories)) +
  geom_point(size=1.5) +
  geom_errorbarh(aes(xmax = clo, xmin = chi, height = 0)) +
  theme_bw() +
  geom_vline(xintercept = 0, colour = "black", linetype = 2, size = .7) +
  facet_grid(categories ~ ., labeller = as_labeller(category_shortnames),
             scales  ="free_y", space = "free_y", switch = "both") +
  scale_y_discrete(position="right") +
  theme(plot.background = element_rect(fill = 'grey95'),
        axis.text.x = element_text(size=11, color = "black"),
        axis.text.y = element_text(size=8.5, color = "black"),
        strip.text.y = element_text(angle = 180, color = "grey15", size = 8.5),
        strip.background = element_rect(fill = 'grey85')) +
  theme(axis.title.y = element_blank(),
        plot.margin=unit(c(1,1,1,3),"line")) +
  scale_x_continuous(limits=c(-1.5, 2)) +
  #scale_x_continuous(labels = c("-.2","-.1","0",".1")) +
  xlab("Donors -- No Priority Status")

# Render plot
plot <- ggplotGrob(base)


# Final plot
grid.newpage()
grid.draw(plot)

dev.print(device = pdf, file="Figure_12_Right_Panel.pdf")












##################Figure 13 - Combined Actors - Bonferroni#################

ptacr <- read_delim("ttest_aid_allocation_bonferroni.txt", 
                    "\t", escape_double = FALSE, trim_ws = TRUE)



# Create intervals
clo <- ptacr$dif - 1.96*ptacr$se
chi <- ptacr$dif + 1.96*ptacr$se

#Create categories
ptacr$categories <- c(rep("Humanitarian",3),
                      rep("Transitional",3),
                      rep("Development",3),
                      rep("Budgetary",3)
              )
                      

ptacr$categories <- factor(ptacr$categories,
                           levels = c( "Humanitarian",
                                      "Transitional",
                                      "Development",
                                      "Budgetary"))

# Create new labels

  ptacr$labels <- c("Strong Violence", "Mild Violence", "Mild Peace" ,
                   "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", "Mild Peace",
                  "Strong Violence", "Mild Violence", 
               	 "Mild Peace")

ptacr$labels <- factor(ptacr$labels,          
                       levels = c("Mild Peace", "Mild Violence",  "Strong Violence",
                                                         "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence",
                                  "Mild Peace", "Mild Violence",  "Strong Violence"))
  
category_shortnames <- c(
  `Humanitarian` = "Humanitarian",
  `Transitional` = "Transitional",
  `Development` = "Development",
  `Budgetary` = "Budgetary"
)



##########################################################################
# Plot 

base <- ggplot(ptacr, aes(y = ptacr$labels, x = ptacr$dif,
                          group=ptacr$categories)) +
  geom_point(size=1.5) +
  geom_errorbarh(aes(xmax = clo, xmin = chi, height = 0)) +
  theme_bw() +
  geom_vline(xintercept = 0, colour = "black", linetype = 2, size = .7) +
  facet_grid(categories ~ ., labeller = as_labeller(category_shortnames),
             scales  ="free_y", space = "free_y", switch = "both") +
  scale_y_discrete(position="right") +
  theme(plot.background = element_rect(fill = 'grey95'),
        axis.text.x = element_text(size=11, color = "black"),
        axis.text.y = element_text(size=8.5, color = "black"),
        strip.text.y = element_text(angle = 180, color = "grey15", size = 8.5),
        strip.background = element_rect(fill = 'grey85')) +
  theme(axis.title.y = element_blank(),
        plot.margin=unit(c(1,1,1,3),"line")) +
  #scale_x_continuous(labels = c("-2","-1","-0.5","0","0.5", "1", "1.5")) +
  scale_x_continuous(limits=c(-1.5, 1.5)) +
  xlab("Difference in Means (Baseline: Strong Peace) - Bonferroni Correction")

# Render plot
plot <- ggplotGrob(base)


# Final plot
grid.newpage()
grid.draw(plot)

dev.print(device = pdf, file="Figure_13.pdf")

